import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileWorkerThread implements Runnable {

	private DataInputStream din;

	public FileWorkerThread(InputStream in) {
		this.din = new DataInputStream(in);
		// this input stream is being wrapped by a dataInputStream
	}

	public void run() {
		FileOutputStream out = null;
		try {
			String fileName = din.readUTF();
			// reading the initial string in the stream
			out = new FileOutputStream(fileName);
			// reading the rest of the bytes
			int c;
			while ((c = din.read()) != -1) {
				out.write(c);
			}

		} catch (IOException e) {
			System.err.println("FileWorkerThread.run: IOException " + e);
			e.printStackTrace();
		} finally {
			try {
				din.close();
				out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
}
